{% extends "forum/forumbase.html" %}

{% comment %}
#    Copyright 2012 New Mexico EPSCoR
#
#    This file is part of Teacher's P.E.T.
#
#    Teacher's P.E.T. is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Teacher's P.E.T. is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Teacher's P.E.T..  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}

{% load files %}

{% block subtitle %} | Forum {% endblock subtitle %}

{% block css %}
    {{block.super}}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/forum.css" >
{% endblock css %}

{% block extra_header %}
	<style type="text/css">
		{% with StartColor='rgb(181,189,200)' EndColor='rgb(40,52,59)' TextColor='#E8E8E8' TitleColor='white' ButtonColor='gray' ButtonTextColor='white'%}
		.forum-thread-index
		{
			color: {{TextColor}};
			background: {{StartColor}}; /* for non-css3 browsers */
		
			filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='{{StartColor}}', endColorstr='{{EndColor}}'); /* for IE */
			
			background-color: #06DCFB; 
			background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from({{StartColor}}), to({{EndColor}}));
			background-image: -webkit-linear-gradient(top, {{StartColor}}, {{EndColor}}); 
			background-image:    -moz-linear-gradient(top, {{StartColor}}, {{EndColor}});
			background-image:     -ms-linear-gradient(top, {{StartColor}}, {{EndColor}});
			background-image:      -o-linear-gradient(top, {{StartColor}}, {{EndColor}});
		}
		.forum-thread-title,
		.forum-thread-header-row,
		.forum-thread-header,
		.forum-thread-footer
		{
			color: {{TitleColor}};
		}
		.forum-thread-entry a:link,
		.forum-thread-entry a:visited
		{
			color: {{TextColor}};
			text-decoration: none;
		}
		.forum-thread-last-entry,
		.forum-thread-last-entry a:link,
		.forum-thread-last-entry a:visited,
		.forum-thread-navigation a,
		.forum-thread-navigation a:link,
		.forum-thread-navigation a:visited
		{
			color: {{TextColor}};
		}
		.forum-thread-create-new .button,
		.forum-thread-create-new .button:link,
		.forum-thread-create-new .button:visited
		{
			color: {{ButtonTextColor}};
			background-color: {{ButtonColor}};
		}
		{% endwith %}
	</style>
{% endblock extra_header %}

{% block content %}
<h1 class="forum-title">{{forum.title}}</h1>
<div class="forum-thread-index">
	<table class="forum-thread-header">
		<tr>
			<td class="forum-thread-create-new">
				{% if not ban or ban.forum_ban < ban.BAN_POSTS %}
					<a class="forum-thread-button" href="{% course_url forum_create_thread %}">New Thread</a>
				{% endif %}
			</td>
			<td class="forum-thread-navigation">
				Page {{page.number}} of {{page.paginator.num_pages}}
				{% if page.has_other_pages %}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
	<table class="forum-thread-table" cellpadding=0 cellspacing=0 border=1>
		<tr class="forum-thread-row forum-thread-header-row"><th></th><th>Thread</th><th>Last Post</th><th>Replies</th></tr>
	{% for thread in page.object_list %}
		{% if not thread.is_deleted %}
		<tr class="forum-thread-row">
			<td class="forum-thread-instructor-assistant-post-data">
				{% if thread.latest_instructor_reply %}
					{% with users|getitem:thread.latest_instructor_reply.author.user.username as User %}
					<a class="forum-thread-instructor-post-link" href="{% course_url forum_view_entries thread_id=thread.id %}?post={{thread.latest_instructor_reply.entry_number}}#post{{thread.latest_instructor_reply.entry_number}}" title="Go to latest instructor post">
						<img src="{% if User.avatar %}{{User.avatar}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="30">
					</a>
					{% endwith %}
				{% endif %}
				{% if thread.latest_assistant_reply %}
					{% with users|getitem:thread.latest_assistant_reply.author.user.username as User %}
					<a class="forum-thread-assistant-post-link" href="{% course_url forum_view_entries thread_id=thread.id %}?post={{thread.latest_assistant_reply.entry_number}}#post{{thread.latest_assistant_reply.entry_number}}" title="Go to latest assistant post">
						<img src="{% if User.avatar %}{{User.avatar}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="30">
					</a>
					{% endwith %}
				{% endif %}
			</td>
			<td class="forum-thread-entry">
				{% if thread.is_sticky %}<span class="forum-thread-sticky">[Sticky]</span> {% endif %}
				<a name="Thread{{thread.id}}" href="{% course_url forum_view_entries thread_id=thread.id %}"
title="{% if thread.first_entry.entry|length > 100%}{{thread.first_entry.entry|slice:":100"|strip_html}}...{%else%}{{thread.first_entry.entry|strip_html}}{%endif%}

{{thread.first_entry.creation_date|date:"M d, Y"}} {{thread.first_entry.creation_date|date:"P"}}
{% if thread.last_entry != thread.first_entry %}Last post by {{thread.last_entry.author.user}} ({{thread.last_entry.creation_date|timesince}} ago){% endif %}">
				<span class="forum-thread-title">{{thread.title}}</span></a>
				{% if thread.is_locked %}<img src="{{STATIC_URL}}images/locked.png" height="15" title="This thread is locked. No changes to this thread are allowed.">{% endif %}
				<br>
				{% with User=users|getitem:thread.first_entry.author.user.username %}
				by <a href="{% course_url apps.participants.views.view_profile username=User.user.username %}">{{User.user.username}} <img src="{% if User.avatar %}{{User.avatar}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="20"></a>
				{% endwith %}
			</td>
			<td class="forum-thread-last-entry">
				{% if thread.last_entry %}
				<a href="{% course_url forum_view_entries thread_id=thread.id %}?post={{thread.last_entry.entry_number}}#post{{thread.last_entry.entry_number}}">
					{{thread.last_entry.creation_date|date:"M d, Y"|spacify}}<br>
					{{thread.last_entry.creation_date|date:"P"|spacify}}<br>
					by {{thread.last_entry.author.user.username}}
				</a>
				{% endif %}
			</td>
			<td class="forum-thread-replies">
				{{thread.last_entry.entry_number}}
			</td>
		</tr>
		{% endif %}
	{% endfor %}
	</table>
	<table class="forum-thread-footer">
		<tr>
			<td class="forum-thread-create-new">
				{% if not ban or ban.forum_ban < ban.BAN_POSTS %}
					<a class="forum-thread-button" href="{% course_url forum_create_thread %}">New Thread</a>
				{% endif %}
			</td>
			<td class="forum-thread-navigation">
				Page {{page.number}} of {{page.paginator.num_pages}}
				{% if page.has_other_pages %}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_thread_page thread_id=TheThread.id page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
</div>
{% endblock content %}